var consumablesApplyUrl = basePath + "/sys/report/schoolProperty/consumablesApply";

var dataGrid;
var schoolId = $("#userSchoolId").val();

$(function() {
	initSchoolIdValue();
	loadData();
});
function loadData() {
	dataGrid = $('#notice').datagrid({
		url : consumablesApplyUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : true,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			startTimeText: $("#startTimeText").val(),
			endTimeText: $("#endTimeText").val(),
			schoolId: schoolId
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [ 
			{
			field : 'id',
			width : 10,
			align : "center",
			checkbox : true
		},
		{ 
			field : 'typeName',
			title : '物品类别',
			resizable : true,
			align : "center",
			width : 10
		},
		{
			field : 'goodsName',
			title : '物品名称',
			width : 15,
			align : "center"
		}, 
		{
			field : 'goodsAttr',
			title : '物品型号',
			width : 15,
			align : "center"
		}, 
		{
			field : 'usedName',
			title : '领用人',
			width : 15,
			align : "center"
		},
		{
			field : 'number',
			title : '数量',
			width : 10,
			align : "center"
		}, 
		{
			field : 'describe',
			title : '领用描述',
			width : 20,
			align : "center"
		}, 
		{
			field : 'createTimeText',
			title : '领用时间',
			width : 10,
			align : "center"
		}
        ]],
		onAfterEdit : function(rowIndex, rowData, changes){
			if(rowData.id){
				changes.id = rowData.id;
				changes.resourceRange = $("#resourceRange").val();
				changes.schoolId = schoolId;
				addmodify(changes);
			}else {
				rowData.resourceRange = $("#resourceRange").val();
				rowData.schoolId = schoolId;
				addmodify(rowData);
			}
		}
	});
}

function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl); 
	$("#" + searchForm).submit();  
}

function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	dataGrid.datagrid('load', $.serializeObject($('#' + formId)));
}
function resetForm(formId) {
	$("#" + formId)[0].reset();
	$("#startTimeText").datebox('setValue', '');
	$("#endTimeText").datebox('setValue', '');
}